class Langzheng < ActiveRecord::Base
   def self.findinfo parent_id,is_directory
      if is_directory!=nil
       find(:all,:conditions =>"user_id=1 and parent_id=#{parent_id} and is_directory=#{is_directory}",:order=>"created_at desc")
      else
       find(:all,:conditions =>"user_id=1 and parent_id=#{parent_id}",:order=>"created_at desc")
      end
    end
   def self.copy ori_id,parent_id
     orifilemodel = find(ori_id)
     newfilemodel = new
     newfilemodel.file_name=orifilemodel.file_name
     newfilemodel.file_size=orifilemodel.file_size
     newfilemodel.is_directory=false
     newfilemodel.user_id=orifilemodel.user_id
     newfilemodel.parent_id=parent_id
     newfilemodel.extend_name=orifilemodel.extend_name
     newfilemodel.file_change_time=orifilemodel.file_change_time
     newfilemodel.file_access_time=orifilemodel.file_access_time
     newfilemodel.save
     newfilemodel
   end
   def self.cut ori_id,parent_id
     newfilemodel = self.copy(ori_id,parent_id)
     orifilemodel = find(ori_id) 
     orifilemodel.destroy
     newfilemodel
   end
   def self.modify_name ori_id,new_name 
     orifilemodel = find(ori_id) 
     orifilemodel.file_name = new_name
     orifilemodel.save
     orifilemodel
   end
   def self.file_delete ori_id  
     destroy ori_id
   end
   def self.folder_create ori_name,parent_id
     newfilemodel = new
     newfilemodel.file_name=ori_name
     newfilemodel.file_size=4096
     newfilemodel.is_directory=true
     newfilemodel.user_id=1
     newfilemodel.parent_id=parent_id 
     newfilemodel.file_change_time=Time.now
     newfilemodel.file_access_time=Time.now
     newfilemodel.save
   end
end
